package com.joy.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.joy.commonutils.R;
import com.joy.eduservice.entity.EduCourse;
import com.joy.eduservice.entity.EduTeacher;
import com.joy.eduservice.service.EduCourseService;
import com.joy.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 焦恩越
 * @create 2021-12-06-16:14
 */
@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class IndexFrontController {
    @Autowired
    private EduCourseService eduCourseService;

    @Autowired
    private EduTeacherService eduTeacherService;

    //查询前八条热门课程，查询前四个名师
    @GetMapping("/index")
    public R index(){
        QueryWrapper<EduCourse> eduCourseWrapper = new QueryWrapper<>();
        eduCourseWrapper.orderByDesc("id");
        eduCourseWrapper.last("limit 8");
        List<EduCourse> eduCourseList = eduCourseService.list(eduCourseWrapper);

        QueryWrapper<EduTeacher> eduTeacherQueryWrapper = new QueryWrapper<>();
        eduTeacherQueryWrapper.orderByDesc("id");
        eduTeacherQueryWrapper.last("limit 4");
        List<EduTeacher> teacherList = eduTeacherService.list(eduTeacherQueryWrapper);

        return R.ok().data("eduList",eduCourseList).data("teacherList",teacherList);
    }

}
